package cate.game.fight.hero.dyn;

import cate.common.table.dynins.DynHeroLevelRow;
import cate.common.table.dynins.DynRuneRow;
import cate.common.table.item.hero.row.HeroBaseRow;
import cate.common.table.item.rune.row.RuneAttrRow;
import cate.game.attr.FightAttr;
import cate.game.role.bag.hero.Hero;

import java.util.List;

public class DynRuneUtil extends DynItemUtil {

	@Override
	public void setUp(Hero hero, HeroBaseRow heroTpl, DynHeroLevelRow itemTpl) {
		if (itemTpl.runeCode <= 0) {
			return;
		}
		DynRuneRow runeRow = ctx.dynInsExcel().rune.get(itemTpl.runeCode);
		if (runeRow == null) {
			return;
		}
		List<DynRuneRow.Config> configs = runeRow.getConfigs(heroTpl.job);
		if (configs == null) {
			return;
		}
		for (DynRuneRow.Config config : configs) {
			for (Integer attr : config.attrs) {
				RuneAttrRow runeAttrRow = ctx.runeExcel().attr.get(attr);
				if (runeAttrRow != null) {
					hero.exPart.addAttr(new FightAttr(runeAttrRow.attrStr));
				}
			}
			for (Integer skill : config.skills) {
				hero.exPart.addSkill(skill);
			}
		}
	}
}
